package CreateCTAxls;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
import xls.Utils;

public class HyperlinkResources
{

  /**
 * @author wed
 * This executable creates the hyperlinks of each pass language.
 * Meaning for the Furkel Pass 5 links are created
 * furkel-pass furkelsattel furkelpas passo-furcia col-du-furkel
 * XLS columns AJ, AK, AL, AM, AN
   */
  public static void main(String[] args) {
    // TODO Auto-generated method stub
    try {
    	Workbook workbook = Workbook.getWorkbook(new File("C:\\XLS\\CTA.xls"));
    	Sheet sheet = workbook.getSheet(15);
    	Cell[] count = sheet.getColumn(0);
    	FileWriter fstream = new FileWriter("C:\\XLS\\hyperlinkresources.txt");
    	BufferedWriter textFile = new BufferedWriter(fstream);
    	for (int i = 1; i < count.length; i++) {
    		Cell passNameENCell = sheet.getCell(4,i);
	        String passNameEN = passNameENCell.getContents();
	        System.out.println(passNameEN);
	        String replaced = Utils.replaceUmlautsDeutsch(passNameEN);
	        String hyphenated  = replaced.replaceAll(" ", "-").substring(0, replaced.length()-8);
	        hyphenated  = hyphenated.toLowerCase();
	        textFile.write(hyphenated);
	        textFile.write("\n");
	    }
    	textFile.write("\n");
    	for (int i = 1; i < count.length; i++) {
    		Cell passNameDECell = sheet.getCell(5,i);
	        String passNameDE = passNameDECell.getContents();
	        System.out.println(passNameDE);
	        String replaced = Utils.replaceUmlautsDeutsch(passNameDE);
	        String hyphenated  = replaced.replaceAll(" ", "-").substring(0, replaced.length()-8);
	        hyphenated  = hyphenated .toLowerCase();
	        textFile.write(hyphenated );
	        textFile.write("\n");
	    }
    	textFile.write("\n");
    	for (int i = 1; i < count.length; i++) {
    		Cell passNameNLCell = sheet.getCell(6,i);
	        String passNameNL = passNameNLCell.getContents();
	        System.out.println(passNameNL);
	        String replaced = Utils.replaceUmlautsDeutsch(passNameNL);
	        String hyphenated  = replaced.replaceAll(" ", "-").substring(0, replaced.length()-8);
	        hyphenated  = hyphenated .toLowerCase();
	        textFile.write(hyphenated );
	        textFile.write("\n");
	    }
    	textFile.write("\n");
    	for (int i = 1; i < count.length; i++) {
    		Cell passNameITCell = sheet.getCell(7,i);
	        String passNameIT = passNameITCell.getContents();
	        System.out.println(passNameIT);
	        String replaced = Utils.replaceUmlautsDeutsch(passNameIT);
	        String hyphenated  = replaced.replaceAll(" ", "-").substring(0, replaced.length()-8);
	        hyphenated  = hyphenated .toLowerCase();
	        textFile.write(hyphenated );
	        textFile.write("\n");
	    }
    	textFile.write("\n");
    	for (int i = 1; i < count.length; i++) {
    		Cell passNameFRCell = sheet.getCell(8,i);
	        String passNameFR = passNameFRCell.getContents();
	        System.out.println(passNameFR);
	        String replaced = Utils.replaceUmlautsDeutsch(passNameFR);
	        String hyphenated  = replaced.replaceAll(" ", "-").substring(0, replaced.length()-8);
	        hyphenated  = hyphenated .toLowerCase();
	        textFile.write(hyphenated );
	        textFile.write("\n");
	    }
    	textFile.close();
    } catch (BiffException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}
